import { GTextFormat } from "../../../../common/GTextFormat";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { QuestionList } from "./QuestionList";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
type int = number;
//class NpcDialog
    
    export  class NpcDialog /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._dialogFormat = new GTextFormat("", 12, 11661311, null, null, null, null, null, null, null, null, null, 5);
            this._dialogFormat.letterSpacing = 2;
            this._dialogText = new Object /* flash.text.TextField */();
            this._dialogText.defaultTextFormat = this._dialogFormat;
            this._dialogText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._dialogText.selectable = false;
            this._dialogText.multiline = true;
            this._dialogText.wordWrap = true;
            this._dialogText.width = 270;
            this._dialogText.filters = [FilterConst.nameGlowFilter];
            addChild(this._dialogText);
            this._questionList = new QuestionList();
            addChild(this._questionList);
            return;
        }

        /* internal  */createTitle(arg1: string): void
        {
            if (this._titleText == null) 
            {
                this._titleText = new Object /* flash.text.TextField */();
                this._titleText.defaultTextFormat = new GTextFormat("", 18, 5358160, true, null, null, null, null, flash.text.TextFormatAlign.CENTER);
                this._titleText.autoSize = flash.text.TextFieldAutoSize.CENTER;
                this._titleText.selectable = false;
                this._titleText.width = 200;
                this._titleText.height = 35;
                this._titleText.filters = [FilterConst.nameGlowFilter];
            }
            this._titleText.text = arg1;
            this._titleText.x = (width - this._titleText.textWidth) / 2 - 5;
            this._titleText.y = this._titlePy;
            if (!this._titleText.parent) 
            {
                addChild(this._titleText);
            }
            if (!this._line) 
            {
                this._line = GlobalClass.getBitmap(ImagesConst.Line);
                this._line.width = 400;
                this._line.x = -40;
            }
            if (!this._line.parent) 
            {
                addChild(this._line);
            }
            this._line.y = this._titleText.y + this._titleText.textHeight + 10;
            return;
        }

        public updateData(arg1: string, arg2: Array<any>=null, arg3: string=null): void
        {
            this._dialogText.htmlText = HTMLUtil.addColor(arg1, "#b1efff");
            if (arg3 == null) 
            {
                this._dialogText.y = 0;
                this._titlePy = 0;
            }
            else 
            {
                this.createTitle(arg3);
                this._dialogText.y = this._line.y + this._line.height + 10;
            }
            if (arg2 && !(arg2.length == 0)) 
            {
                this.updateQuestionList(arg2);
            }
            return;
        }

        public updateQuestionList(arg1: Array<any>): void
        {
            this._questionList.updateData(arg1);
            this._questionList.y = this._dialogText.y + this._dialogText.height + 10;
            return;
        }

        public dispose(): void
        {
            if (this._titleText) 
            {
                this._titleText.text = "";
                if (this._titleText.parent) 
                {
                    removeChild(this._titleText);
                }
            }
            if (this._line && this._line.parent) 
            {
                removeChild(this._line);
            }
            this._titlePy = -10;
            this._dialogText.text = "";
            this._questionList.dispose();
            return;
        }

        public /* override */ set width(arg1: number)
        {
            super.width = arg1;
            this._dialogText.width = arg1;
            if (this._titleText) 
            {
                this._titleText.width = arg1;
            }
            return;
        }

        public /* override */ get height(): number
        {
            return this._dialogText.y + this._dialogText.textHeight + this._questionList.height + this._titlePy;
        }

        /* internal */ /* var */_titleText: Object /* flash.text.TextField */;

        /* internal */ /* var */_line: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_dialogText: Object /* flash.text.TextField */;

        /* internal */ /* var */_dialogFormat: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_questionList: QuestionList;

        /* internal */ /* var */_titlePy: int=-10;
    }
